package cn.tedu.csmall.stock.webapi.quartz;

import cn.tedu.csmall.stock.webapi.config.RabbitConfig;
import org.quartz.Job;
import org.quartz.JobExecutionContext;
import org.quartz.JobExecutionException;
import org.springframework.amqp.rabbit.core.RabbitTemplate;
import org.springframework.beans.factory.annotation.Autowired;

import java.time.LocalDateTime;

public class QuartzJob implements Job {
    //利用RabbitTamplate工具类，操作rabbitMQ
    @Autowired
    private RabbitTemplate rabbitTemplate;
    @Override
    public void execute(JobExecutionContext jobExecutionContext) throws JobExecutionException {
        //写要执行的任务
//        System.out.println("==========="+LocalDateTime.now()+"===========");
        //获取当前时间，发送到RabbitMQ中
        LocalDateTime now = LocalDateTime.now();
        //convertAndSend()方法可以帮我们把消息转成byte[]类型并发送
        rabbitTemplate.convertAndSend(RabbitConfig.STOCK_EXCHANGE,RabbitConfig.STOCK_ROUTE,now);
    }
}
